package com.helpustotravel.model.dao;

import java.util.List;

import javax.jdo.PersistenceManager;
import javax.jdo.Query;

import com.helpustotravel.core.DAOBase;
import com.helpustotravel.model.jdo.Position;

public class PositionDAO extends DAOBase {

	public PositionDAO(PersistenceManager pm) {
		super(pm);
	}
	
	public Position addPosition(Position position) {
		try {
			return pm.makePersistent(position);
		} finally {
			
		}
	}
	
	@SuppressWarnings("unchecked")
	public Position getPosition(String travellerName, long id) {
		Query query = pm.newQuery("select from " + Position.class.getName() + 
				" where travellerName == travellerNameParam " + 
				"&& id == idParam " + 
				"parameters String travellerNameParam, long idParam ");
		
		List<Position> positions = (List<Position>)query.execute(travellerName, id);
		
		if(positions.size() > 0) {
			return positions.get(0);
		} else {
			return null;
		}
	}
}
